package com.xiaodou.mjf.infrastructure.common.app;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import org.springframework.data.domain.Page;

import com.xiaodou.mjf.infrastructure.common.entity.CommonEntity;

/**
 * Created by Rocky on 15/3/24.
 */
public abstract class MyBatisSimpleService<T extends CommonEntity,ID extends Serializable> implements CommonService<T,ID> {

    protected abstract Mapper<T,ID> getMapper();

    public T get(ID id){
        return getMapper().get(id);
    }

    public T save(T entity){
        ID id = getMapper().insert(entity);
        return entity;
    }

    public void update(T entity){
        getMapper().update(entity);
    }

    public void delete(ID id){
        getMapper().delete(id);
    }

    public List<T> list(){
        return getMapper().list();
    }

    public List<T> list(T entity){
        return getMapper().list(entity);
    }

    public Integer count(T entity){
        return getMapper().count(entity);
    }
   
	@Override
	public void save(Collection<T> entities) {
		for(T entity:entities){
			save(entity);
		}
	}

	@Override
	public void delete(T entity) {
		
	}

	@Override
	public boolean exits(ID id) {
		return false;
	}

	@Override
	public Page<T> page(T entity) {
		// TODO Auto-generated method stub
		return null;
	}
}
